package com.senlingspace.web.controller.headquarters;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjTicketLevel;
import com.senlingspace.system.service.ISlkjTicketLevelService;
import com.senlingspace.common.core.page.TableDataInfo;

/**
 * 票档管理Controller
 *
 * @author SenlingSpace
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/system/level")
public class SlkjTicketLevelController extends BaseController {
    @Autowired
    private ISlkjTicketLevelService slkjTicketLevelService;

    /**
     * 查询票档管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjTicketLevel slkjTicketLevel) {
        List<SlkjTicketLevel> list = slkjTicketLevelService.selectSlkjTicketLevelList(slkjTicketLevel);
        return getDataTable(list);
    }

    /**
     * 获取票档管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(slkjTicketLevelService.selectSlkjTicketLevelById(id));
    }

    /**
     * 新增票档管理
     */
    @PreAuthorize("@ss.hasPermi('system:level:add')")
    @Log(title = "票档管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjTicketLevel slkjTicketLevel) {
        slkjTicketLevel.setName(slkjTicketLevel.getName().trim());
        int count = slkjTicketLevelService.countTicketLevelByName(slkjTicketLevel.getName(), null);
        if (count > 0) {
            return AjaxResult.error("票档名称已存在！");
        }
        slkjTicketLevel.setCreateBy(super.getUserId() + "");
        return toAjax(slkjTicketLevelService.insertSlkjTicketLevel(slkjTicketLevel));
    }

    /**
     * 修改票档管理
     */
    @PreAuthorize("@ss.hasPermi('system:level:edit')")
    @Log(title = "票档管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjTicketLevel slkjTicketLevel) {
        slkjTicketLevel.setName(slkjTicketLevel.getName().trim());
        int count = slkjTicketLevelService.countTicketLevelByName(slkjTicketLevel.getName(), slkjTicketLevel.getId());
        if (count > 0) {
            return AjaxResult.error("票档名称已存在！");
        }
        slkjTicketLevel.setUpdateBy(super.getUserId() + "");
        return toAjax(slkjTicketLevelService.updateSlkjTicketLevel(slkjTicketLevel));
    }

    /**
     * 删除票档管理
     */
    @PreAuthorize("@ss.hasPermi('system:level:remove')")
    @Log(title = "票档管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return slkjTicketLevelService.deleteSlkjTicketLevelByIds(ids, super.getUserId());
    }

    /**
     * 票档列表下拉框
     * 页面查询组件使用
     *
     * @param slkjTicketLevel
     * @return {@link AjaxResult }
     */
    @GetMapping("/ticketLevelSelected")
    public AjaxResult ticketLevelSelected(SlkjTicketLevel slkjTicketLevel) {
        List<SlkjTicketLevel> list = slkjTicketLevelService.selectSlkjTicketLevelList(slkjTicketLevel);
        return success(list);
    }

}
